home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / inventor / sharedSV / SoSceneViewer.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  14.0 KB  |  437 lines

  1. /*
  2.  * Copyright (c) 1991, 1992 Silicon Graphics, Inc.
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that the name of Silicon Graphics may not be used in any advertising or
  7.  * publicity relating to the software without the specific, prior written
  8.  * permission of Silicon Graphics.
  9.  *
  10.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
  11.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
  12.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  13.  *
  14.  * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  15.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
  16.  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF THE
  17.  * POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN
  18.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  19.  */
  20.  
  21. //  -*- C++ -*-
  22.  
  23. /*
  24.  * Copyright (C) 1990,91   Silicon Graphics, Inc.
  25.  *
  26.  _______________________________________________________________________
  27.  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
  28.  |
  29.  |   $Revision: 1.1007 $
  30.  |
  31.  |   Classes    : SoSceneViewer
  32.  |
  33.  |   Author(s)    : Thad Beier, Alain Dumesny, David Mott, Paul Isaacs
  34.  |
  35.  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
  36.  _______________________________________________________________________
  37.  */
  38.  
  39. #ifndef  _SCENE_VIEWER_
  40. #define  _SCENE_VIEWER_
  41.  
  42. #include <X11/Intrinsic.h>
  43. #include <Xm/Xm.h>
  44. #include <Xm/RowColumn.h>
  45.  
  46. #include <Inventor/nodes/SoNode.h>
  47. #include <Inventor/SbPList.h>
  48. #include <Inventor/nodes/SoPerspectiveCamera.h>
  49. #include <Inventor/actions/SoGLRenderAction.h>    // transparency levels
  50. #include <Inventor/actions/SoCallbackAction.h>
  51. #include <Inventor/viewers/SoXtFullViewer.h>
  52.  
  53. // components
  54. class    SoXtColorEditor;
  55. class    SoXtFileBrowser;
  56. class    SoXtMaterialEditor;
  57. class    SoXtPrintDialog;
  58. class    SoXtTransformSliderSet;
  59. class    SoXtClipboard;
  60. class    SoXtDirectionalLightEditor;
  61.  
  62. // interaction
  63. class    SoLineHighlight;
  64. class    SoBoxHighlight;
  65. class    SoHighlight;
  66. class    SoSelection;
  67.  
  68. // nodes
  69. class    SoDataSensor;
  70. class    SoDirectionalLight;
  71. class    SoEnvironment;
  72. class    SoGroup;
  73. class    SoLabel;
  74. class    SoMaterial;
  75. class    SoSceneViewer;
  76. class   SoSwitch;
  77. class    SoLight;
  78. class    SoTransform;
  79.  
  80. // misc.
  81. class    SvManipList;
  82.  
  83. enum SvEViewer {
  84.     SV_VWR_EXAMINER = 0, 
  85.     SV_VWR_FLY, 
  86.     SV_VWR_WALK, 
  87.     SV_VWR_PLANE, 
  88. };
  89.  
  90. enum SvEManipMode {
  91.     SV_NONE,                         // None
  92.     SV_TRACKBALL,                    // Trackball manip
  93.     SV_HANDLEBOX,                    // Handlebox manip
  94.     SV_JACK,                         // Jack manip
  95.     SV_XFBOX,                        // TransformBox manip
  96.     SV_DRAGPOINT                     // DragPoint manip
  97. };
  98.  
  99. struct    SoSceneViewerData;
  100. struct    SvLightData;
  101.  
  102. //////////////////////////////////////////////////////////////////////////////
  103. //
  104. //  Class: SoSceneViewer
  105. //
  106. //      The SceneViewer component lets you select between different viewers
  107. //  (Examiner, Navigator,..) and lets you perform  some simple attribute
  108. //  assignment, and some manipulation of data.
  109. //
  110. //////////////////////////////////////////////////////////////////////////////
  111.  
  112. class SoSceneViewer : public SoXtComponent {
  113.   public:
  114.     
  115.     // Constructor:
  116.     // envFile is the environment file to use. This is where the camera,
  117.     // environment node, and lights are found. 
  118.     // Passing NULL means use the default environment.
  119.     //
  120.     // Save will save all the children of root, not including root itself.
  121.     // Save Environment will save the lights and camera environment into envFile
  122.     //
  123.     SoSceneViewer(SoSelection *root, const char *envFile = NULL);
  124.     ~SoSceneViewer();
  125.     
  126.     //
  127.     // Camera operation routines
  128.     //
  129.     void    viewAll()        { currentViewer->viewAll(); }
  130.     void           viewSelection();
  131.     void    saveHomePosition()  { currentViewer->saveHomePosition(); }
  132.     void        setCamera(SoCamera *cam) { currentViewer->setCamera(cam); }
  133.     SoCamera    *getCamera()        { return camera; }
  134.     
  135.     //
  136.     // Before new data is sent to the viewer, the newData method should
  137.     // be called to disconnect all manipulators and highlights
  138.     //
  139.     void            newData();
  140.     
  141.     // Show/hide the pulldown menu bar (default shown)
  142.     void        showMenu(SbBool onOrOff);
  143.     SbBool        isMenuShown()        { return showMenuFlag; }
  144.     
  145.     // Show/hide the viewer component trims (default shown)
  146.     void                setDecoration(SbBool onOrOff)    { currentViewer->setDecoration(onOrOff); }
  147.     SbBool              isDecoration()        { return currentViewer->isDecoration(); }
  148.     
  149.     // Show/hide headlight (default on) and get to the headlight node.
  150.     void                setHeadlight(SbBool onOrOff)    { currentViewer->setHeadlight(onOrOff); }
  151.     SbBool              isHeadlight()        { return currentViewer->isHeadlight(); }
  152.     SoDirectionalLight    *getHeadlight()        { return currentViewer->getHeadlight(); }
  153.     
  154.     //
  155.     // Sets/gets the current drawing style in the main view
  156.     // (default VIEW_AS_IS)
  157.     //
  158.     void                setDrawStyle(SoXtViewer::DrawStyle style)
  159.                         { currentViewer->setDrawStyle(style); }
  160.     SoXtViewer::DrawStyle        getDrawStyle()
  161.                         { return currentViewer->getDrawStyle(); }
  162.     
  163.     //
  164.     // Sets/gets the current buffering type in the main view
  165.     // (default BUFFER_INTERACTIVE on Indigo, BUFFER_DOUBLE otherwise)
  166.     //
  167.     void                setBufferingType(SoXtViewer::BufferType type)
  168.                         { currentViewer->setBufferingType(type); }
  169.  
  170.     SoXtViewer::BufferType getBufferingType()
  171.                         { return currentViewer->getBufferingType(); }
  172.  
  173.     // Turn viewing on/off (Default to on) in the viewers.
  174.     void                setViewing(SbBool onOrOff)  { currentViewer->setViewing(onOrOff); }
  175.     SbBool              isViewing()    { return currentViewer->isViewing(); }
  176.     
  177.     // Set/get the level of transparency type
  178.     void        setTransparencyType(SoGLRenderAction::TransparencyType type)
  179.                     { currentViewer->setTransparencyType(type); }
  180.     SoGLRenderAction::TransparencyType    getTransparencyType()
  181.                     { return currentViewer->getTransparencyType(); }
  182.  
  183.     // Grabs render area pixel contents
  184.     unsigned long    *copyScreen( short &numRows, short &numColumns )
  185.                     { return currentViewer->copyScreen(numRows, numColumns); }
  186.     
  187.     // returns the current render area widget
  188.     Widget        getRenderAreaWidget()    { return currentViewer->getRenderAreaWidget(); }
  189.     
  190. #ifdef EXPLORER
  191.     // redraw the scene
  192.     void        render() { currentViewer->render(); }
  193.  
  194.     // change the camera
  195.     void        changeCamera(SoCamera *newcamera);
  196.  
  197.     // set the EXPLORER user mode callback routine
  198.     void        setUserModeEventCallback(SoXtRenderAreaEventCB *fcn);
  199. #endif /* EXPLORER */
  200.     SbBool    readEnvFile(const char *filename);
  201.     SbBool    writeEnvFile(const char *filename);
  202.     SbBool    BroadcastEnv();
  203.     SbBool    ReadBroadcastEnv();
  204.     SoGroup             *lightsCameraEnvironment;
  205.  
  206.  protected:
  207.     // redefine these
  208.     virtual const char *    getDefaultWidgetName() const;
  209.     virtual const char *    getDefaultTitle() const;
  210.     virtual const char *    getDefaultIconTitle() const;
  211.     
  212.  private:
  213.     // Scene graph data
  214.     SoSelection            *selection;            // the same user supplied graph
  215.     SoSeparator     *sceneGraph;        // user supplied scene graph
  216.     
  217.     // Lights, camera, environment!
  218. //    SoGroup             *lightsCameraEnvironment;
  219.     SoLabel             *envLabel;
  220.     SoCamera        *camera;
  221.     SoEnvironment       *environment;
  222.     SoGroup             *lightGroup;
  223.     
  224.     void            createLightsCameraEnvironment();
  225.     
  226.     // Selection highlight
  227.     SoLineHighlight     *lineHighlight;
  228.     SoBoxHighlight      *boxHighlight;
  229.     
  230.     //
  231.     // Widgets and menus
  232.     //
  233.     
  234.     Widget        mgrWidget;  // our topmost form widget
  235.     Widget        menuWidget; // topbar menu widget
  236.     SbBool        showMenuFlag;
  237.     SoSceneViewerData    *menuItems; // list of menu items data
  238.     
  239.     virtual Widget     buildWidget(Widget parent, const char *name);
  240.     void        buildAndLayoutMenu(Widget parent);
  241.     void        buildAndLayoutViewer(SoXtFullViewer *vwr);
  242.  
  243.     // callback for all menu buttons to perform action
  244.     static void            processTopbarEvent(Widget, SoSceneViewerData *,
  245.                    XmAnyCallbackStruct *);
  246.     // callback when a menu is displayed
  247.     static void        menuDisplay(Widget, SoSceneViewerData *, XtPointer);
  248.     
  249.     // this is called after objects are added/deleted or the selection changes
  250.     void        updateCommandAvailability();
  251.     
  252.     //
  253.     // File
  254.     //
  255.     
  256.     // file reading methods
  257.     int        fileMode;
  258.     char    *fileName;
  259.     SbBool    useShowcaseBrowser;
  260.     void    getFileName();
  261.     void    doFileIO(const char *filename);
  262.     SbBool        readFile(const char *filename);
  263.     SbBool    writeFile(const char *filename);
  264. //    SbBool    readEnvFile(const char *filename);
  265. //    SbBool    writeEnvFile(const char *filename);
  266.     void    deleteScene();
  267.     void    save();
  268.     void    removeCameras(SoGroup *root);
  269.     
  270.     // motif vars for file reading/writting
  271.     Widget        fileDialog;
  272.     static void         fileDialogCB(Widget, SoSceneViewer *,
  273.                                     XmFileSelectionBoxCallbackStruct *);
  274.     
  275.     // showcase file browser vars
  276.     SoXtFileBrowser       *browser;
  277.     static void         browserCB(void *userData, const char *filename);
  278.     
  279.     // printing vars
  280.     SoXtPrintDialog       *printDialog;
  281.     void                print();
  282.     static void         beforePrintCallback(void *uData, SoXtPrintDialog *);
  283.     static void         afterPrintCallback(void *uData, SoXtPrintDialog *);
  284.     SoHighlight        *savedHighlight;
  285.     SbBool        feedbackShown;
  286.     
  287.     void        showAboutDialog();
  288.     
  289.     //
  290.     // Edit
  291.     //
  292.     
  293.     // Select parent, if there is one; select everything.
  294.     void        pickParent();
  295.     void        pickAll();
  296.  
  297.     // for copy and paste
  298.     SoXtClipboard        *clipboard;     // copy/paste 3d data
  299.  
  300.     // Paste callback - invoked when paste data transfer is complete
  301.     void                pasteDone(SoPathList *pathList);
  302.     static void        pasteDoneCB(void *userData, SoPathList *pathList);
  303.     
  304.     
  305.     //
  306.     // Viewing
  307.     //
  308.     
  309.     SoXtFullViewer    *viewerList[4];    // list of viewers
  310.     SvEViewer        whichViewer;    // current viewer ID
  311.     SoXtFullViewer    *currentViewer;    // current viewer pt
  312.     
  313.     void                switchToViewer(SvEViewer newViewer);
  314.     
  315.     // Environment: fog, antialiasing
  316.     SbBool        fogFlag;        // Fog on/off
  317.     void        setFog(SbBool onOrOff);    // Turns fog on/off
  318.     SbBool        antialiasingFlag;    // AA-ing on/off
  319.     void        setAntialiasing(SbBool onOrOff); // Turns AA-ing on/off
  320.     
  321.     // Background color
  322.     SoXtColorEditor       *backgroundColorEditor;
  323.     const SbColor &    getBackgroundColor()    { return currentViewer->getBackgroundColor(); }
  324.     void        editBackgroundColor();    // Invokes color editor on bkg
  325.     static void            backgroundColorCallback(void *userData,
  326.                 const SbColor *color);
  327.     
  328.     //
  329.     // Editors
  330.     //
  331.     
  332.     SbBool              ignoreCallback;
  333.     SoMaterial         *findMaterialForAttach( const SoPath *target );
  334.     SoPath             *findTransformForAttach( const SoPath * target );
  335.     // callback used by Accum state action created by findMaterialForAttach
  336.     static SoCallbackAction::Response findMtlPreTailCB(void *data, 
  337.                         SoCallbackAction *accum,
  338.                         const SoNode *);
  339.     
  340.     // transform slider set
  341.     SoXtTransformSliderSet *transformSliderSet;
  342.     void        createTransformSliderSet();
  343.  
  344.     // Material editor
  345.     SoXtMaterialEditor      *materialEditor;
  346.     void                createMaterialEditor();
  347.     
  348.     // Color editor
  349.     SoXtColorEditor       *colorEditor;
  350.     void        createColorEditor();
  351.  
  352.  
  353.     //
  354.     // Manips
  355.     //
  356.     SvEManipMode curManip;
  357.     SbBool       curManipReplaces;
  358.     SvManipList     *maniplist;    // list of path/manip ptr pairs
  359.  
  360.     // replaces manips with the given type for all selected objects.
  361.     void    replaceAllManips( SvEManipMode manipType );
  362.  
  363.     // attaches a manipulator
  364.     void    attachManip( SvEManipMode manipType, SoPath *p );
  365.     void    attachManipToAll( SvEManipMode manipType );
  366.  
  367.     // detaches a manipulator
  368.     void    detachManip( SoPath *p );
  369.     void    detachManipFromAll();
  370.  
  371.  
  372.     //
  373.     // Lighting
  374.     //
  375.     
  376.     SbPList        lightDataList;
  377.     SoXtDirectionalLightEditor *headlightEditor;
  378.     SvLightData        *headlightData;
  379.     void        addLight(SoLight *light);
  380.     SvLightData        *addLightEntry(SoLight *light, SoSwitch *lightSwitch);
  381.     void        addLightMenuEntry(SvLightData *);
  382.     void        turnLightOnOff(SvLightData *data, SbBool flag);
  383.     static void        lightToggleCB(Widget, SvLightData *, void *);
  384.     void        editLight(SvLightData *data, SbBool flag);
  385.     static void        editLightToggleCB(Widget, SvLightData *, void *);
  386.     static void        editLightColorCB(Widget, SvLightData *, void *);
  387.     void        removeLight(SvLightData *);
  388.     static void        removeLightCB(Widget, SvLightData *, void *);
  389.     static void        lightSubmenuDisplay(Widget, SvLightData *, void *);
  390.     
  391.     // vars to make the light manips all the same size
  392.     SbBox3f        lightManipSize;
  393.     SbBool        calculatedLightManipSize;
  394.     
  395.     // temporary remove/add the light manip geometry of the attached manips
  396.     // (used for file writting and printing)
  397.     void        removeAttachedLightManipGeometry();
  398.     void        addAttachedLightManipGeometry();
  399.     
  400.     // Ambient lighting color
  401.     SoXtColorEditor       *ambientColorEditor;
  402.     void        editAmbientColor();    // Invokes color editor on amb
  403.     static void            ambientColorCallback(void *userData,
  404.                 const SbColor *color);
  405.     
  406.     //
  407.     // Selection
  408.     //
  409.     // manages changes in the selection.
  410.     static void     deselectionCallback(void *userData, SoPath *obj);
  411.     static void     selectionCallback(void *userData, SoPath *obj);
  412.  
  413.     // change highlight color with a color editor
  414.     SoXtColorEditor       *highlightColorEditor;
  415.     void                editHighlightColor();
  416.     static void            highlightColorCallback(void *userData,
  417.                 const SbColor *color);
  418.     
  419.     
  420.     //
  421.     // Convenience routines
  422.     //
  423.     static SbBool    isAffectedByTransform( SoNode *node );
  424.     static SbBool    isAffectedByMaterial( SoNode *node );
  425.  
  426. #ifdef EXPLORER
  427.     //
  428.     // user pick function
  429.     //
  430.     SoXtRenderAreaEventCB   *userModeCB;
  431.     void            *userModedata;
  432.     SbBool            userModeFlag;
  433. #endif /* EXPLORER */
  434. };
  435.  
  436. #endif  /* _SCENE_VIEWER_ */
  437.